import 'package:flutter/material.dart';

class LoadingView extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _State();

}

class _State extends State<LoadingView> with SingleTickerProviderStateMixin {

  late AnimationController animationController;
  late Animation coloranim;

  @override
  void initState() {
    super.initState();
    animationController = AnimationController(vsync: this, duration: const Duration(milliseconds: 1500));

    coloranim = Tween(begin: 0.0, end: 1.0).animate(animationController);
    animationController.repeat();
  }

  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Center(
        child: AnimatedBuilder(
          animation: coloranim,
          builder: (ctx, child) {
            double value = coloranim.value;
            return ShaderMask(shaderCallback: (Rect bounds) {
              return LinearGradient(
                  begin: Alignment.bottomLeft,
                  end: Alignment.topRight,
                  stops: [value - 0.2, value, value, value + 0.2],
                  colors: const [
                Color(0xff00ff00),
                Color(0xffff0000),
                Color(0xffff0000),
                Color(0xff00ff00),
              ]).createShader(bounds);
            }, blendMode: BlendMode.srcATop,
            child: const Text("数据加载中", style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)));
          },
        ),
      ),
    );
  }

}